package gui;
import javax.swing.AbstractButton;
import javax.swing.JPanel;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JSeparator;

import controllers.ManagerUIP;
import controllers.OBLSettings;
import controllers.WelcomeUIP;

import java.awt.Button;
import java.awt.Graphics;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import javax.swing.SwingConstants;
import messagesPacks.*;
import Entity.*;
import messagesPacks.ActivityReportMessage;
import messagesPacks.BorrowStatisticsMSG;

import javax.swing.ImageIcon;
import javax.swing.Icon;
import java.awt.SystemColor;
/**
 * @author Ariel Brucker
 * The UI CLASS FOR THE MAIN SCREEN FOR THE MANAGER(GUI AND ACTIONLISTENNERS)
 */
public class ManagerMainUI extends JPanel 
{
	private static final long serialVersionUID = 1L;
	
	public ManagerViewEmployeesUI managerViewEmployeesUI=null;
	public ManagerLatenessReportUI managerLatenessReportUI=null;
	public ManagerBorrowReportUI managerBorrowReportUI=null;
	public ManagerActivityReportUI managerActivityUI = null ; 
	public ManagerUIP muip = null;
	public ManagerSuspendSub managerSuspendSub;
	public LibrarianUI librerianUI = null;
	private JLabel lblOblManager;
	public JButton btnLogout;
	public JButton btnExit;
	private final JSeparator separator = new JSeparator();
	private JButton btnActivityReport;
	private JButton btnBorrowReport;
	private JButton btnLatenessReport;
	private JButton btnCustomReport;
	private JButton btnViewEmployees;
	private JButton btnSuspendSubscriber; 
	private JButton btnGoToLibrarianOpt;
	public JButton btnLibBack;
	private JSeparator separator_1;
    JLabel WelcomeLabel;
    private JLabel backgroundlabel;
	
	public ManagerMainUI() 
	{
		super();
		muip = new ManagerUIP();
		initialize();
	}
	private void initialize()
	{
		setLayout(null);
		this.setSize(OBLSettings.pane2Size[0],OBLSettings.pane2Size[1]);
		
		btnLogout = new JButton("Logout");
		btnLogout.setFont(new Font("Tahoma", Font.BOLD, 15));
		btnLogout.setBounds(614, 11, 83, 41);
		add(btnLogout);
		
		lblOblManager = new JLabel("OBL Manager");
		lblOblManager.setFont(new Font("Tahoma", Font.BOLD, 20));
		lblOblManager.setBounds(324, 0, 152, 58);
		add(lblOblManager);
		separator.setBounds(0, 57, 855, 14);
		add(separator);
		
		btnExit = new JButton("Exit");
		btnExit.setFont(new Font("Tahoma", Font.BOLD, 15));
		btnExit.setBounds(707, 11, 83, 41);
		add(btnExit);
		
		btnActivityReport = new JButton("Activity Report");
		btnActivityReport.setFont(new Font("Tahoma", Font.PLAIN, 15));
		btnActivityReport.setBounds(25, 110, 159, 41);
		add(btnActivityReport);
		
		btnBorrowReport = new JButton("Borrow Report");
		btnBorrowReport.setFont(new Font("Tahoma", Font.PLAIN, 15));
		btnBorrowReport.setBounds(25, 173, 159, 41);
		add(btnBorrowReport);
		
		btnLatenessReport = new JButton("Lateness Report");
		btnLatenessReport.setFont(new Font("Tahoma", Font.PLAIN, 15));
		btnLatenessReport.setBounds(25, 304, 159, 41);
		add(btnLatenessReport);
		
		btnCustomReport = new JButton("Custom Report");
		btnCustomReport.setFont(new Font("Tahoma", Font.PLAIN, 15));
		btnCustomReport.setBounds(25, 238, 159, 41);
		add(btnCustomReport);
		
		btnViewEmployees = new JButton("View Employees");
		btnViewEmployees.setFont(new Font("Tahoma", Font.PLAIN, 15));
		btnViewEmployees.setBounds(25, 479, 159, 41);
		add(btnViewEmployees);

		btnSuspendSubscriber = new JButton("Suspend Subscriber");
		btnSuspendSubscriber.setFont(new Font("Tahoma", Font.PLAIN, 15));
		btnSuspendSubscriber.setBounds(25, 411, 159, 41);
		add(btnSuspendSubscriber);

		btnGoToLibrarianOpt = new JButton("Librarian options");
		btnGoToLibrarianOpt.setFont(new Font("Tahoma", Font.PLAIN, 15));
		btnGoToLibrarianOpt.setBounds(386, 479, 177, 41);
		add(btnGoToLibrarianOpt);
		
		separator_1 = new JSeparator();
		separator_1.setBounds(-43, 366, 272, 20);
		add(separator_1);
		
		JSeparator separator_2 = new JSeparator();
		separator_2.setOrientation(SwingConstants.VERTICAL);
		separator_2.setBounds(229, 57, 15, 309);
		add(separator_2);
		
		JSeparator separator_3 = new JSeparator();
		separator_3.setOrientation(SwingConstants.VERTICAL);
		separator_3.setBounds(229, 354, 30, 272);
		add(separator_3);
		
		JLabel lblReports = new JLabel("Reports");
		lblReports.setFont(new Font("Tahoma", Font.BOLD, 16));
		lblReports.setBounds(70, 77, 83, 27);
		add(lblReports);
		
		JLabel lblOperations = new JLabel("Operations");
		lblOperations.setFont(new Font("Tahoma", Font.BOLD, 15));
		lblOperations.setBounds(57, 379, 116, 27);
		add(lblOperations);
		
		WelcomeLabel = new JLabel("");
		WelcomeLabel.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 22));
		WelcomeLabel.setBounds(12, 11, 247, 41);
		WelcomeLabel.setVisible(false);
		add(WelcomeLabel);
		
		btnLibBack = new JButton("Back");
		btnLibBack.setBounds(26, 11, 83, 41);
		btnLibBack.setFont(new Font("Tahoma", Font.BOLD, 15));
		
		managerActivityUI = new  ManagerActivityReportUI(getManagerMainUI());
		managerSuspendSub = new ManagerSuspendSub(getManagerMainUI());
		managerViewEmployeesUI = new ManagerViewEmployeesUI(getManagerMainUI());
		managerBorrowReportUI = new ManagerBorrowReportUI(getManagerMainUI());
		managerLatenessReportUI=new ManagerLatenessReportUI(getManagerMainUI());
		
		backgroundlabel = new JLabel("");
		backgroundlabel.setIcon(OBLSettings.IMG_MANAGERMAINUI);
		backgroundlabel.setBounds(0, 57, 800, 543);
		add(backgroundlabel);
	    
		
		librerianUI = new LibrarianUI(); 
		librerianUI.btnExit.addActionListener(WelcomeUI.exitActionL);
		librerianUI.btnLogout.addActionListener(WelcomeUI.logoutActionL);
//================================================================		
//                      Action Listeners
//================================================================		
		btnActivityReport.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				managerActivityUI.showActivity();
				   WelcomeUI.wui.switchPanel("OBL Manager-Activity Report" +
					 		"",managerActivityUI ,OBLSettings.pane2Size[0], OBLSettings.pane2Size[1]);
				   
			}
		});
//================================================================			
		btnSuspendSubscriber.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e) 
			{
				
			   WelcomeUI.wui.switchPanel("OBL Manager-Suspend Subscribers" +
			 		"",managerSuspendSub ,OBLSettings.pane2Size[0], OBLSettings.pane2Size[1]);
				
			}
		});
//================================================================
		btnBorrowReport.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e) 
			{
				managerBorrowReportUI.borrowStatisticsMSG=muip.CreateBorrowReport();	
			   WelcomeUI.wui.switchPanel("OBL Manager-Borrow Report" +
			 		"",managerBorrowReportUI ,OBLSettings.pane2Size[0], OBLSettings.pane2Size[1]);
				
			}
		});
		
//================================================================		
		btnViewEmployees.addActionListener(new ActionListener() 
		{
			public void actionPerformed(ActionEvent arg0) 
			{
				managerViewEmployeesUI.usersMSG=muip.ViewAllEmployees();
				WelcomeUI.wui.switchPanel("OBL Manager-View Employees", managerViewEmployeesUI
						            ,OBLSettings.pane2Size[0], OBLSettings.pane2Size[1]);
			}
		});
//================================================================	
		btnGoToLibrarianOpt.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent arg0)
			{

				librerianUI.add(btnLibBack);
				WelcomeUI.wui.switchPanel("Librarian Options", librerianUI
			            ,OBLSettings.pane2Size[0], OBLSettings.pane2Size[1]);
			}
		});
		
		btnLibBack.addActionListener(new ActionListener() 
		{
			public void actionPerformed(ActionEvent e) 
			{
                 WelcomeUI.wui.switchPanel("OBL Manager ", getManagerMainUI() ,
                		 OBLSettings.pane2Size[0], OBLSettings.pane2Size[1]);
			}
		});

//================================================================		
		btnLatenessReport.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e) 
			{
				managerLatenessReportUI.managerLatenessReportMSG=muip.CreateLatenessReport();
				WelcomeUI.wui.switchPanel("OBL Manager-Lateness Report", managerLatenessReportUI
			            ,OBLSettings.pane2Size[0], OBLSettings.pane2Size[1]);
				
			}
		});
		
	}//init
	
	
//===================================================================	
//	                 Getters & Setters
//===================================================================	
	public ManagerMainUI getManagerMainUI()
	{
		return this;
	}
	public ManagerUIP getManagerUIP()
	{
		return this.muip;
	}
	
	public void paintComponent(Graphics g) 
	{
		g.drawImage((OBLSettings.IMG_DEFAULT_BACKGROUND).getImage(), 0, 0, OBLSettings.pane2Size[0], OBLSettings.pane2Size[1],null);
		
	}
	
	
	
	
}
